﻿
using System.Collections.Generic;
using UnityEngine;


public class PatientManager : MonoBehaviour
{
    public static PatientManager Instance;
    public List<Patient> patients = new List<Patient>();
    private void Awake()
    {

            Instance = this;

            // 核心修改：获取所有层级的子对象中的 Patient 组件
            CollectChildPatients();


    }

    /// <summary>
    /// 递归收集所有子对象的 Patient 组件
    /// </summary>
    private void CollectChildPatients()
    {
        patients.Clear(); // 清空旧数据

        // 获取当前对象的所有子对象（包含未激活的）
        Transform[] allChildren = GetComponentsInChildren<Transform>(true);

        foreach (Transform child in allChildren)
        {
            // 跳过父对象自身
            if (child == transform) continue;

            Patient patient = child.GetComponent<Patient>();
            if (patient != null && !patients.Contains(patient))
            {
                patients.Add(patient);
            }
        }

        Debug.Log($"已收集到 {patients.Count} 个患者");




    }
}
